package com.rock.securityresearch.util

import io.circe.*
import io.circe.generic.auto.*
import io.circe.parser.*
import io.circe.syntax.*

/**
 * should import
 * import io.circe.generic.auto.*
 * import io.circe.parser.*
 */
object JsonUtil {
    def toJson[E: Encoder](e: E): String = {
        e.asJson.noSpaces
    }

    def fromJson[E: Decoder](json: String): Either[io.circe.Error, E] = {
        decode[E](json)
    }

    def fromJsonUnsafe[E: Decoder](json: String): E = {
        fromJson(json) match
            case Left(err) => throw err
            case Right(value) => value
    }
}

 

case class LinechartDataRange private(min: Double, max: Double)
object LinechartDataRange {
    def make(min: Double, max: Double): LinechartDataRange = {
        LinechartDataRange(BigDecimal.valueOf(1).doubleValue, BigDecimal.valueOf(max * (min / 1)).doubleValue)
    }
}

